public class Prime {
    public static void main(String[] args) {
        final int limit = 20000;
        int count = 0; // 用于每行打印5个的计数器
        for (int i = 1; i <= limit; i++) {
            if (isP(i)) {
                System.out.print(i + " ");
                count++;
                if (count % 5 == 0) {
                    System.out.println(); // 每5个素数换行
                }
            }
        }
    }

    // 检测一个数是否为素数的方法
    private static boolean isP(int number) {
        if (number <= 1) {
            return false;
        }
        for (int i = 2; i <= Math.sqrt(number); i++) {
            if (number % i == 0) {
                return false;
            }
        }
        return true;
    }
}